<template>
  <div class="card content-box">
    <el-form ref="ruleFormRef" :rules="rules" :model="formData" label-width="160px">
      <div v-auth="'CMED'">
        <el-form-item class="item" :label="$t('jggl.gsxx.companyName') + ' :'" prop="orgName">
          <el-input v-model="formData.orgName" />
        </el-form-item>
        <el-form-item class="item" :label="$t('jggl.gsxx.companyPhone') + ' :'" prop="officePhone">
          <el-input v-model="formData.officePhone" />
        </el-form-item>
        <el-form-item class="item" :label="$t('jggl.gsxx.faxNumber') + ' :'" prop="officeFax">
          <el-input v-model="formData.officeFax" />
        </el-form-item>
        <el-form-item class="item" :label="$t('jggl.gsxx.companyEmail') + ' :'" prop="email">
          <el-input v-model="formData.email" />
        </el-form-item>
        <el-form-item class="item" :label="$t('jggl.gsxx.companyAddress') + ' :'">
          <el-input v-model="formData.address" />
        </el-form-item>
        <el-form-item class="item" :label="$t('jggl.gsxx.companyWebsite') + ' :'">
          <el-input v-model="formData.homePage" />
        </el-form-item>
        <!-- <el-form-item class="item" :label="$t('jggl.gsxx.systemName') + ' :'">
          <el-input v-model="formData.itsmname" />
        </el-form-item> -->
        <el-form-item>
          <el-button type="primary" @click="onSubmit(ruleFormRef)">{{ $t("jggl.gsxx.save") }}</el-button>
        </el-form-item>
      </div>
      <el-tabs v-model="activeName">
        <div v-auth="'EMED'">
          <el-tab-pane :label="$t('jggl.gsxx.sendEmail')" name="first">
            <el-form :model="fsyxData" label-width="200px">
              <el-form-item class="item" :label="$t('jggl.gsxx.emailServiceType') + ' :'">
                <el-radio v-model="fsyxData.emailType" label="normal">{{ $t("jggl.gsxx.normalEmailServer") }}</el-radio>
                <el-radio v-model="fsyxData.emailType" label="exchange">{{ $t("jggl.gsxx.exchangeEmailServer") }}</el-radio>
              </el-form-item>
            </el-form>
            <el-form v-if="fsyxData.emailType == 'normal'" :model="fsyxData" label-width="200px">
              <el-form-item class="item" :label="$t('jggl.gsxx.yourName') + ' :'">
                <el-input v-model="fsyxData.personal" />
              </el-form-item>
              <el-form-item class="item" :label="$t('jggl.gsxx.sendEmailAddress') + ' :'">
                <el-input v-model="fsyxData.personalEmailAddress" :placeholder="$t('jggl.gsxx.yourName') + '[email@mail.com]'" />
              </el-form-item>
              <el-form-item class="item" :label="$t('jggl.gsxx.emailAccount') + ' :'">
                <el-input v-model="fsyxData.userName" />
              </el-form-item>
              <el-form-item class="item" :label="$t('jggl.gsxx.password') + ' :'">
                <el-input v-model="fsyxData.password" type="password" show-password />
              </el-form-item>
              <el-form-item class="item" :label="$t('jggl.gsxx.smtpService')"></el-form-item>
              <el-form-item class="item" :label="$t('jggl.gsxx.emailServerAddress') + ' :'">
                <el-input v-model="fsyxData.smtpServerAddress" />
              </el-form-item>
              <el-form-item class="item" :label="$t('jggl.gsxx.emailServerPort') + ' :'">
                <el-input v-model="fsyxData.smtpServerPort" :placeholder="$t('jggl.gsxx.port25')" />
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="onSubmitfsyx">{{ $t("jggl.gsxx.save") }}</el-button>
                <el-button type="primary" @click="linktestfsyxpt">{{ $t("jggl.gsxx.connectTest") }}</el-button>
              </el-form-item>
            </el-form>
            <el-form v-if="fsyxData.emailType != 'normal'" :model="fsyxData" label-width="200px">
              <el-form-item class="item" :label="$t('jggl.gsxx.yourName') + ' :'">
                <el-input v-model="fsyxData.personal" :placeholder="$t('jggl.gsxx.yourName') + '[email@mail.com]'" />
              </el-form-item>
              <el-form-item class="item" :label="$t('jggl.gsxx.server') + ' :'">
                <el-input v-model="fsyxData.exchangeHostName" />
                <el-select v-model="fsyxData.emailVersion">
                  <el-option label="Exchange 2007_SP1" value="Exchange 2007_SP1" />
                  <el-option label="Exchange 2010" value="Exchange 2010" />
                  <el-option label="Exchange 2010_SP1" value="Exchange 2010_SP1" />
                  <el-option label="Exchange 2010_SP2" value="Exchange 2010_SP2" />
                </el-select>
              </el-form-item>
              <el-form-item class="item" :label="$t('jggl.gsxx.domain') + ' :'">
                <el-input v-model="fsyxData.domain" />
              </el-form-item>
              <el-form-item class="item" :label="$t('jggl.gsxx.loginAccount') + ' :'">
                <el-input v-model="fsyxData.exchangeUserName" />
              </el-form-item>
              <el-form-item class="item" :label="$t('jggl.gsxx.password') + ' :'">
                <el-input v-model="fsyxData.exchangePassword" type="password" show-password />
              </el-form-item>
              <el-form-item class="item" :label="$t('jggl.gsxx.emailAccount') + ' :'">
                <el-input v-model="fsyxData.exchangeEmailAccount" />
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="onSubmitfsyx">{{ $t("jggl.gsxx.save") }}</el-button>
                <el-button type="primary" @click="linktestfsyxexchange">{{ $t("jggl.gsxx.connectTest") }}</el-button>
              </el-form-item>
            </el-form>
          </el-tab-pane>
          <el-tab-pane :label="$t('jggl.gsxx.receiveEmail')" name="second">
            <el-form :model="jsyxData" label-width="200px">
              <el-form-item class="item" :label="$t('jggl.gsxx.emailServiceType') + ' :'">
                <el-radio v-model="jsyxData.emailType" label="Receive">{{ $t("jggl.gsxx.normalEmailServer") }}</el-radio>
                <el-radio v-model="jsyxData.emailType" label="Receive_exchange">{{
                  $t("jggl.gsxx.exchangeEmailServer")
                }}</el-radio>
              </el-form-item>
            </el-form>
            <el-form :model="jsyxData" v-if="jsyxData.emailType == 'Receive'" label-width="200px">
              <el-form-item class="item" :label="$t('jggl.gsxx.yourName') + ' :'">
                <el-input v-model="jsyxData.personal" />
              </el-form-item>
              <el-form-item class="item" :label="$t('jggl.gsxx.receiveEmail') + ' :'">
                <el-input v-model="jsyxData.personalEmailAddress" :placeholder="$t('jggl.gsxx.yourName') + '[email@mail.com]'" />
              </el-form-item>
              <el-form-item class="item" :label="$t('jggl.gsxx.emailAccount') + ' :'">
                <el-input v-model="jsyxData.userName" />
              </el-form-item>
              <el-form-item class="item" :label="$t('jggl.gsxx.password') + ' :'">
                <el-input type="password" v-model="jsyxData.password" show-password />
              </el-form-item>
              <el-form-item class="item" :label="$t('jggl.gsxx.pop3Service')"></el-form-item>
              <el-form-item class="item" :label="$t('jggl.gsxx.emailServerAddress') + ' :'">
                <el-input v-model="jsyxData.smtpServerAddress" />
              </el-form-item>
              <el-form-item class="item" :label="$t('jggl.gsxx.emailServerPort') + ' :'">
                <el-input v-model="jsyxData.smtpServerPort" :placeholder="$t('jggl.gsxx.port110')" />
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="onSubmitjsyx">{{ $t("jggl.gsxx.save") }}</el-button>
                <el-button type="primary" @click="linktestjsyx">{{ $t("jggl.gsxx.connectTest") }}</el-button>
              </el-form-item>
            </el-form>
            <el-form v-if="jsyxData.emailType != 'Receive'" :model="jsyxData" label-width="200px">
              <el-form-item class="item" :label="$t('jggl.gsxx.yourName') + ' :'">
                <el-input v-model="jsyxData.personal" :placeholder="$t('jggl.gsxx.yourName') + '[email@mail.com]'" />
              </el-form-item>
              <el-form-item class="item" :label="$t('jggl.gsxx.server') + ' :'">
                <el-input v-model="jsyxData.exchangeHostName" />
                <el-select v-model="jsyxData.emailVersion">
                  <el-option label="Exchange 2007_SP1" value="Exchange 2007_SP1" />
                  <el-option label="Exchange 2010" value="Exchange 2010" />
                  <el-option label="Exchange 2010_SP1" value="Exchange 2010_SP1" />
                  <el-option label="Exchange 2010_SP2" value="Exchange 2010_SP2" />
                </el-select>
              </el-form-item>
              <el-form-item class="item" :label="$t('jggl.gsxx.domain') + ' :'">
                <el-input v-model="jsyxData.domain" />
              </el-form-item>
              <el-form-item class="item" :label="$t('jggl.gsxx.loginAccount') + ' :'">
                <el-input v-model="jsyxData.exchangeUserName" />
              </el-form-item>
              <el-form-item class="item" :label="$t('jggl.gsxx.password') + ' :'">
                <el-input v-model="jsyxData.exchangePassword" />
              </el-form-item>
              <el-form-item class="item" :label="$t('jggl.gsxx.emailAccount') + ' :'">
                <el-input v-model="jsyxData.exchangeEmailAccount" />
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="onSubmitjsyx">{{ $t("jggl.gsxx.save") }}</el-button>
                <el-button type="primary" @click="linktestjsyxexchange">{{ $t("jggl.gsxx.connectTest") }}</el-button>
              </el-form-item>
            </el-form>
          </el-tab-pane>
        </div>
        <div v-auth="'SMMG'">
          <el-tab-pane :label="$t('jggl.gsxx.smsAccount')" name="third">
            <el-form :model="smsAccountDTO" label-width="200px">
              <el-form-item class="item" :label="$t('jggl.gsxx.smsProvider') + ' :'">
                <el-select v-model="smsAccountDTO.smsInstance" clearable :placeholder="$t('jggl.gsxx.pleaseSelect')">
                  <el-option :label="$t('jggl.gsxx.pleaseSelect')" value="" />
                  <el-option :label="$t('jggl.gsxx.mobileBusiness')" value="WanCiSMSHelper" />
                  <el-option :label="$t('jggl.gsxx.xinZhiSMS')" value="PanZhiSMSHelper" />
                  <el-option :label="$t('jggl.gsxx.other')" value="OtherSMSHelper" />
                </el-select>
              </el-form-item>
              <el-form-item
                v-if="smsAccountDTO.smsInstance == 'PanZhiSMSHelper'"
                class="item"
                :label="$t('jggl.gsxx.orgNumber') + ' :'"
              >
                <el-input v-model="smsAccountDTO.orgId" />
              </el-form-item>
              <el-form-item class="item" :label="$t('jggl.gsxx.smsAccountName') + ' :'">
                <el-input v-model="smsAccountDTO.userName" />
              </el-form-item>
              <el-form-item class="item" :label="$t('jggl.gsxx.smsPassword') + ' :'">
                <el-input v-model="smsAccountDTO.pwd" />
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="onSubmitdxzh">{{ $t("jggl.gsxx.save") }}</el-button>
                <el-button type="primary" @click="testaccount">{{ $t("jggl.gsxx.connectTest") }}</el-button>
              </el-form-item>
            </el-form>
          </el-tab-pane>
        </div>
        <div v-auth="'SMMG'">
          <el-tab-pane :label="$t('jggl.gsxx.wechatIntegration')" name="fore">
            <el-form :model="smsAccountDTO" label-width="200px" ref="smsAccountRuleFormRef" :rules="smsAccountRules">
              <el-form-item class="item" :label="$t('jggl.gsxx.enterpriseId') + ' :'" prop="weComCorpid">
                <el-input v-model="smsAccountDTO.weComCorpid" />
              </el-form-item>
              <el-form-item class="item" :label="$t('jggl.gsxx.appId') + ' :'" prop="weComAgentId">
                <el-input v-model="smsAccountDTO.weComAgentId" />
              </el-form-item>
              <el-form-item class="item" :label="$t('jggl.gsxx.appSecret') + ' :'" prop="weComAgentSecret">
                <el-input v-model="smsAccountDTO.weComAgentSecret" />
              </el-form-item>
              <el-form-item class="item" :label="$t('jggl.gsxx.accessTokenApi') + ' :'" prop="weComTokenUrl">
                <el-input v-model="smsAccountDTO.weComTokenUrl" placeholder="https://qyapi.weixin.qq.com/cgi-bin/gettoken" />
              </el-form-item>
              <el-form-item class="item" :label="$t('jggl.gsxx.userInfoApi') + ' :'" prop="weComUserinfoUrl">
                <el-input
                  v-model="smsAccountDTO.weComUserinfoUrl"
                  placeholder="https://qyapi.weixin.qq.com/cgi-bin/auth/getuserinfo"
                />
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="onsaveWecomeConfig(smsAccountRuleFormRef)">{{
                  $t("jggl.gsxx.save")
                }}</el-button>
                <el-button type="primary" @click="testAccessToken">{{ $t("jggl.gsxx.connectTest") }}</el-button>
              </el-form-item>
            </el-form>
          </el-tab-pane>
        </div>
        <div v-auth="'SMMG'">
          <el-tab-pane :label="$t('jggl.gsxx.assetSync')" name="fire">
            <el-button type="primary" @click="yuehaiImportCiBtn">{{ $t("jggl.gsxx.syncAsset") }}</el-button>
            <el-button type="primary" @click="yuehaiImportCi2Btn">同步分类</el-button>
          </el-tab-pane>
        </div>
      </el-tabs>
    </el-form>
  </div>
</template>

<script setup lang="ts" name="basicForm">
import { ElMessage, FormInstance, FormRules } from "element-plus";
import { ref, reactive, onMounted, onBeforeUnmount } from "vue";
import {
  getjggl,
  emailtest,
  emailtestexchange,
  testSMSAccount,
  getjgglmessage,
  mergeCompany,
  saveWecomConfig,
  findWecomConfig,
  testToken,
  yuehaiImportCi,
  yuehaiImportCi2,
  findServereMail,
  findReceiveServiceMail,
  showPagesSet,
  updatePagesSet
} from "@/api/modules/jggl";
import { Base64 } from "js-base64";
import { isTelOrFax, isEmail } from "@/utils/eleValidate";
import { useAuthButtons } from "@/hooks/useAuthButtons";
import { useI18n } from "vue-i18n";

const { t } = useI18n();
const { BUTTONS } = useAuthButtons();
onMounted(() => {
  //加载公司信息
  getjgglmessage().then(res => {
    let newParams = JSON.parse(JSON.stringify(res));
    console.log(newParams);
    formData.orgName = newParams.companyName;
    formData.email = newParams.email;
    formData.address = newParams.address;
    formData.homePage = newParams.homePage;
    formData.officeFax = newParams.officeFax;
    formData.officePhone = newParams.officePhone;
  });
  showPagesSet().then(res => {
    console.log(res);
    let newParams = JSON.parse(JSON.stringify(res));
    formData.itsmname = newParams.paName;
  });
  findWecomConfig().then(res => {
    let newParams = JSON.parse(JSON.stringify(res));
    console.log(newParams);
    smsAccountDTO.weComCorpid = newParams.weComCorpid;
    smsAccountDTO.weComAgentSecret = newParams.weComAgentSecret;
    smsAccountDTO.weComAgentId = newParams.weComAgentId;
    smsAccountDTO.tomcatDeployPort = newParams.tomcatDeployPort;
    smsAccountDTO.weComUserinfoUrl = newParams.weComUserinfoUrl;
    smsAccountDTO.weComTokenUrl = newParams.weComTokenUrl;
  });
  findServereMail().then(res => {
    let newParams = JSON.parse(JSON.stringify(res));
    fsyxData.emailType = newParams.emailType;
    fsyxData.personal = newParams.personal;
    fsyxData.personalEmailAddress = newParams.personalEmailAddress;
    fsyxData.userName = newParams.userName;
    fsyxData.password = newParams.password;
    fsyxData.smtpServerAddress = newParams.smtpServerAddress;
    fsyxData.smtpServerPort = newParams.smtpServerPort;
    fsyxData.exchangeHostName = newParams.exchangeHostName;
    fsyxData.emailVersion = newParams.emailVersion;
    fsyxData.domain = newParams.domain;
    fsyxData.exchangeUserName = newParams.exchangeUserName;
    fsyxData.exchangePassword = newParams.exchangePassword;
    fsyxData.exchangeEmailAccount = newParams.exchangeEmailAccount;

    // emailType: "Receive",
    // personal: "",
    // personalEmailAddress: "",
    // userName: "",
    // password: "",
    // smtpServerAddress: "",
    // smtpServerPort: "",
    // exchangeHostName: "",
    // emailVersion: "Exchange 2007_SP1",
    // domain: "",
    // exchangeUserName: "",
    // exchangePassword: "",
    // exchangeEmailAccount: ""
  });
  findReceiveServiceMail().then(res => {
    let newParams = JSON.parse(JSON.stringify(res));

    jsyxData.personal = newParams.personal;
    jsyxData.personalEmailAddress = newParams.personalEmailAddress;
    jsyxData.userName = newParams.userName;
    jsyxData.password = newParams.password;
    jsyxData.smtpServerAddress = newParams.smtpServerAddress;
    jsyxData.smtpServerPort = newParams.smtpServerPort;
    jsyxData.exchangeHostName = newParams.exchangeHostName;
    jsyxData.emailVersion = newParams.emailVersion;
    jsyxData.domain = newParams.domain;
    jsyxData.exchangeUserName = newParams.exchangeUserName;
    jsyxData.exchangePassword = newParams.exchangePassword;
    jsyxData.exchangeEmailAccount = newParams.exchangeEmailAccount;
    // emailType: "Receive",
  });
});
const ruleFormRef = ref<FormInstance>();
const smsAccountRuleFormRef = ref<FormInstance>();
const activeName = ref("first");
const formData = reactive({
  orgName: "",
  officePhone: "",
  officeFax: "",
  email: "",
  address: "",
  homePage: "",
  orgNo: "",
  itsmname: ""
});
const fsyxData = reactive({
  emailType: "normal",
  personal: "",
  personalEmailAddress: "",
  userName: "",
  password: "",
  smtpServerAddress: "",
  smtpServerPort: "",
  exchangeHostName: "",
  emailVersion: "Exchange 2007_SP1",
  domain: "",
  exchangeUserName: "",
  exchangePassword: "",
  exchangeEmailAccount: "",
  emailServerId: 1
});
const emailConnectionDto = reactive({
  smtphost: "",
  smtpport: "",
  username: "",
  password: ""
});
const emailConnectionDtojs = reactive({
  pop3host: "",
  pop3port: "",
  username: "",
  password: ""
});
const smsAccountDTO = reactive({
  smsInstance: "",
  orgId: "",
  userName: "",
  pwd: "",
  smsLength: 70,
  moblieCount: 99,

  weComCorpid: "",
  weComAgentSecret: "",
  weComAgentId: "",
  weComtongxunlusecret: "",
  tomcatDeployPort: "",
  weComUserinfoUrl: "",
  weComTokenUrl: ""
});

const jsyxData = reactive({
  emailType: "Receive",
  personal: "",
  personalEmailAddress: "",
  userName: "",
  password: "",
  smtpServerAddress: "",
  smtpServerPort: "",
  exchangeHostName: "",
  emailVersion: "Exchange 2007_SP1",
  domain: "",
  exchangeUserName: "",
  exchangePassword: "",
  exchangeEmailAccount: ""
});

const onSubmit = async (formEl: FormInstance | undefined) => {
  if (!formEl) return;
  await formEl.validate((valid, fields) => {
    if (valid) {
      updatePagesSet(formData.itsmname).then(res => {
        console.log(res);
      });
      mergeCompany(formData, "organizationDto").then(res => {
        ElMessage.success(t("common.saveSuccess"));
        window.location.reload();
      });
    } else {
      ElMessage.error(t("common.pleaseFillFormCorrectly"));
    }
  });
};

const onsaveWecomeConfig = async (formEl: FormInstance | undefined) => {
  if (!formEl) return;
  await formEl.validate((valid, fields) => {
    if (valid) {
      testToken(smsAccountDTO, "smsAccountDTO").then(res => {
        if (res.toString() == "true") {
          saveWecomConfig(smsAccountDTO, "smsAccountDTO").then(res => {
            ElMessage.success(t("common.saveSuccess"));
          });
        } else {
          ElMessage.error(t("jggl.gsxx.getAccessTokenFailed"));
        }
      });
    } else {
      ElMessage.error(t("common.pleaseFillFormCorrectly"));
    }
  });
};

const yuehaiImportCiBtn = () => {
  console.log(t("jggl.gsxx.syncAssetApi"));
  yuehaiImportCi();
};
const yuehaiImportCi2Btn = () => {
  // console.log(t("jggl.gsxx.syncAssetApi"));
  yuehaiImportCi2();
};

const testAccessToken = () => {
  if (smsAccountDTO.weComCorpid == "") {
    ElMessage.error(t("jggl.gsxx.pleaseEnterEnterpriseId"));
    return;
  }
  if (smsAccountDTO.weComAgentSecret == "") {
    ElMessage.error(t("jggl.gsxx.pleaseEnterSecret"));
    return;
  }
  if (smsAccountDTO.weComTokenUrl == "") {
    ElMessage.error(t("jggl.gsxx.pleaseEnterAccessTokenUrl"));
    return;
  }
  testToken(smsAccountDTO, "smsAccountDTO").then(res => {
    if (res.toString() == "true") {
      ElMessage.success(t("jggl.gsxx.getSuccess"));
    } else {
      ElMessage.error(t("jggl.gsxx.getFailed"));
    }
  });
};

//判断是否加密过
const isBase64 = (str: string) => {
  // 正则表达式：检查是否是有效的 Base64 编码字符串
  const base64Regex = /^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)?$/;
  // 判断是否符合 Base64 的格式
  return base64Regex.test(str);
};

const onSubmitfsyx = () => {
  if (!isBase64(fsyxData.password)) {
    fsyxData.password = Base64.encode(fsyxData.password);
  }
  getjggl(fsyxData, "emailServerDTO").then(res => {
    ElMessage.success(t("common.saveSuccess"));
  });
};

const linktestfsyxpt = () => {
  emailConnectionDto.smtphost = fsyxData.smtpServerAddress;
  emailConnectionDto.smtpport = fsyxData.smtpServerPort;
  emailConnectionDto.username = fsyxData.userName;
  emailConnectionDto.password = fsyxData.password;
  emailtest(emailConnectionDto, "emailConnectionDto").then(res => {
    console.log(res);
    if (res.toString() != "0") {
      ElMessage.error(t("jggl.gsxx.emailConnectionFailed"));
    } else {
      ElMessage.success(t("jggl.gsxx.connectionSuccess"));
    }
  });
};

const linktestfsyxexchange = () => {
  emailtestexchange(fsyxData, "emailServerDTO").then(res => {
    if (res.toString() == "true") {
      ElMessage.success(t("jggl.gsxx.connectionSuccess"));
    } else {
      ElMessage.error(t("jggl.gsxx.emailConnectionFailed"));
    }
  });
};

const onSubmitjsyx = () => {
  getjggl(jsyxData, "emailServerDTO").then(res => {
    ElMessage.success(t("common.saveSuccess"));
  });
};

const linktestjsyx = () => {
  emailConnectionDtojs.pop3host = jsyxData.smtpServerAddress;
  emailConnectionDtojs.pop3port = jsyxData.smtpServerPort;
  emailConnectionDtojs.username = fsyxData.userName;
  emailConnectionDtojs.password = fsyxData.password;
  emailtest(emailConnectionDtojs, "emailConnectionDto").then(res => {
    if (res.toString() != "0") {
      ElMessage.error(t("jggl.gsxx.emailConnectionFailed"));
    } else {
      ElMessage.success(t("jggl.gsxx.connectionSuccess"));
    }
  });
};

const linktestjsyxexchange = () => {
  emailtestexchange(jsyxData, "emailServerDTO").then(res => {
    if (res.toString() == "true") {
      ElMessage.success(t("jggl.gsxx.connectionSuccess"));
    } else {
      ElMessage.error(t("jggl.gsxx.emailConnectionFailed"));
    }
  });
};

const onSubmitdxzh = () => {
  testSMSAccount(smsAccountDTO, "smsAccountDTO");
};

const testaccount = () => {
  ElMessage.success(t("jggl.gsxx.testAccount"));
};

const rules = reactive<FormRules>({
  orgName: [
    { required: true, message: t("jggl.gsxx.pleaseEnterCompanyName"), trigger: "blur" },
    { min: 2, message: t("jggl.gsxx.lengthAtLeastTwo"), trigger: "blur" }
  ],
  officePhone: [{ required: false, validator: isTelOrFax, trigger: "blur" }],
  officeFax: [{ required: false, validator: isTelOrFax, trigger: "blur" }],
  email: [{ required: false, validator: isEmail, trigger: "blur" }]
});

const smsAccountRules = reactive<FormRules>({
  weComCorpid: [{ required: true, trigger: "blur", message: t("jggl.gsxx.pleaseEnterEnterpriseId") }],
  weComAgentSecret: [{ required: true, trigger: "blur", message: t("jggl.gsxx.pleaseEnterSecret") }],
  weComAgentId: [{ required: true, trigger: "blur", message: t("jggl.gsxx.pleaseEnterAppId") }],
  tomcatDeployPort: [{ required: true, trigger: "blur", message: t("jggl.gsxx.pleaseEnterTomcatPort") }],
  weComUserinfoUrl: [{ required: true, trigger: "blur", message: t("jggl.gsxx.pleaseEnterUserInfoUrl") }],
  weComTokenUrl: [{ required: true, trigger: "blur", message: t("jggl.gsxx.pleaseEnterAccessTokenUrl") }]
});
</script>

<style scoped lang="scss">
@import "./index";
.item {
  width: 500px;
}
</style>
